package com.ruoyi.business.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.HsVillage;
import com.ruoyi.business.service.IHsVillageService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 小区Controller
 * 
 * @author asher
 * @date 2021-11-08
 */
@RestController
@RequestMapping("/business/village")
public class HsVillageController extends BaseController
{
    @Autowired
    private IHsVillageService hsVillageService;

    /**
     * 查询小区列表
     */
    @GetMapping("/list")
    public TableDataInfo list(HsVillage hsVillage)
    {
        startPage();
        List<HsVillage> list = hsVillageService.selectHsVillageList(hsVillage);
        return getDataTable(list);
    }

    /**
     * 导出小区列表
     */
    @PreAuthorize("@ss.hasPermi('business:village:export')")
    @Log(title = "小区", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HsVillage hsVillage)
    {
        List<HsVillage> list = hsVillageService.selectHsVillageList(hsVillage);
        ExcelUtil<HsVillage> util = new ExcelUtil<HsVillage>(HsVillage.class);
        return util.exportExcel(list, "小区数据");
    }

    /**
     * 获取小区详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:village:query')")
    @GetMapping(value = "/{villageId}")
    public AjaxResult getInfo(@PathVariable("villageId") Long villageId)
    {
        return AjaxResult.success(hsVillageService.selectHsVillageByVillageId(villageId));
    }

    /**
     * 新增小区
     */
    @PreAuthorize("@ss.hasPermi('business:village:add')")
    @Log(title = "小区", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HsVillage hsVillage)
    {
        return toAjax(hsVillageService.insertHsVillage(hsVillage));
    }

    /**
     * 修改小区
     */
    @PreAuthorize("@ss.hasPermi('business:village:edit')")
    @Log(title = "小区", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HsVillage hsVillage)
    {
        return toAjax(hsVillageService.updateHsVillage(hsVillage));
    }

    /**
     * 删除小区
     */
    @PreAuthorize("@ss.hasPermi('business:village:remove')")
    @Log(title = "小区", businessType = BusinessType.DELETE)
	@DeleteMapping("/{villageIds}")
    public AjaxResult remove(@PathVariable Long[] villageIds)
    {
        return toAjax(hsVillageService.deleteHsVillageByVillageIds(villageIds));
    }
}
